From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Wed, 11 Sep 2024 16:29:56 +0000 (-0600) Subject: use persistant docker container for GUI (#1338) X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2^2~54 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22Program/%22http:/www.example.com/cgi/%22https:/%22Program?a=commitdiff_plain;h=508001149a507bc24f426e4ff93bdc4560c4bc70;p=gpsbabel.git use persistant docker container for GUI (#1338) --- diff --git a/tools/archive_images/run_gpsbabelfe.sh b/tools/archive_images/run_gpsbabelfe.sh index 3ddcfbc2d..31fd56b62 100755 --- a/tools/archive_images/run_gpsbabelfe.sh +++ b/tools/archive_images/run_gpsbabelfe.sh @@ -3,19 +3,41 @@ VERSION=latest while getopts "v:" opt; do case $opt in v) VERSION=$OPTARG;; - *) exit 1;; + *) echo "Usage: $0 [-v tag]"; exit 1;; esac done shift $((OPTIND -1)) -if [ -n "$LANG" ]; then - OPTIONS+=(-e "LANG=$LANG") -fi +# we use a persistent container so the gpsbabel GUI state is saved and restored (in the container). +container_name=tsteven4_gpsbabel_${VERSION} + +# if the container doesn't exist create it. +if [ -z "$(docker ps -a -q -f "name=^${container_name}$")" ]; then + if [ -n "$LANG" ]; then + OPTIONS+=(-e "LANG=$LANG") + fi + + docker container create -q -i -t \ + -e "DISPLAY=$DISPLAY" \ + "${OPTIONS[@]}" \ + --name "${container_name}" \ + --network=host \ + -v "$(pwd):/app" \ + -v "$HOME/.Xauthority:/root/.Xauthority" \ + -v /tmp/.X11-unix:/tmp/.X11-unix \ + -w /app \ + "tsteven4/gpsbabel:${VERSION}" >/dev/null -container=$(docker create -q -i -t -w /app -v "$(pwd):/app" --network=host -v "$HOME/.Xauthority:/root/.Xauthority" -v /tmp/.X11-unix:/tmp/.X11-unix -e "DISPLAY=$DISPLAY" "${OPTIONS[@]}" "tsteven4/gpsbabel:${VERSION}") -trap 'docker rm -f "${container}" >/dev/null' 0 1 2 3 15 -docker start "${container}" >/dev/null -docker exec -i -t "${container}" setup_user.sh "$(id -u)" "$(id -g)" -docker exec -i -t -u "$(id -u):$(id -g)" "${container}" gpsbabelfe "$@" + docker start "${container_name}" >/dev/null +# make sure the users uid/gid exist in the container. + docker exec -i -t "${container_name}" setup_user.sh "$(id -u)" "$(id -g)" +fi + +# if necessary start the container. +if [ -z "$(docker ps -a -q -f "status=running" -f "name=^${container_name}$")" ]; then + docker start "${container_name}" >/dev/null +fi +# run the gpsbabel GUI +docker exec -i -t -u "$(id -u):$(id -g)" "${container_name}" gpsbabelfe "$@"